15. Extensions: Class-based Flexibility Create an Overlay Class Y.Overlay = Y.Base.build("overlay", Y.Widget, [ Widget-Position, // Positioning Widget-Position-Ext, // Adv. Positioning Widget-Stack, // Shim/Stack Support Widget-StdMod // Header/Body/Footer ]);
16. Extensions: Reuse Reuse only the extensions desired for Tooltip Y.Tooltip = Y.Base.build("tooltip", Y.Widget, [ Widget-Position, // Positioning Widget-Stack // Shim/Stack Support ]);
17. Plug-in: Instance-based Flexibility Instance of Overlay, adding io support var ioOverlay = new Y.Overlay(...); ioOverlay.plug(Y.OverlayIOPlugin, { url: "http://host.foo.com/getOverlayContent" }); ioOverlay.io.refreshContent();
18. Plug-in: Instance-based Override Instance of Overlay, adding Animation Support var animOverlay = new Y.Overlay(...); animOverlay.plug(Y.WidgetAnimPlugin); animOverlay.show(); animOverlay.hide();
19.
20. Event Façades // DOM Event linkNode.on("click", function(e) { if (!e.target.hasClass("selector")) { e.preventDefault(); } }); // Custom Event slider.on("valueChange", function(e) { if (e.newVal < 200) { e.preventDefault(); } });
21. Event Aspect in YUI 2 // Publisher show : function() { if (this.fire("beforeShow")) { YAHOO.util.Dom.removeClass(node, "hidden"); this.fire("show"); } } // Subscriber overlay.subscribe("beforeShow", function(t, args) { if (!taskSelected) { return false; } } overlay.subscribe("show", function(t, args) {...});
23. Event Flow: On -> Default -> After ON ON Default Behavior After After After this.fire("select"); e.stopImmediatePropagation() e.preventDefault() e.preventDefault() e.stopImmediatePropagation()
24. Bubbling: Delegation Beyond the DOM Menu.prototype = { addItem : function(menuItem) { var menu = this; menuItem.addTarget(menu); }, initializer : function() { this.on("menuitem:select", this._itemSelect); } } menu.getItem(2).on("select", function(e) { // Handle select for item 2, don’t bubble to Menu e.stopPropagation(); ... } Event Bubbling: Delegation Beyond the DOM
25. Event Flow : Bubbling Menu MenuItem ON ON Default After After After this.fire("menuitem:select"); ON Default After After e.stopPropagation()
35. Node is the single point for DOM access, throughout YUI 3. Makes YUI 3 ideal as a trusted source in protected environments such as Caja and Ad-Safe. Constrained by Façades
36. var items = Y.Node.all(".actions li"); items.addClass("disabled"); items.set("title", "Item Disabled"); items.each(function(node) { node.addClass("disabled); node.set("title", "Item Disabled"); }); NodeList: Operations a on Node Collection